#include<iostream>
#include<vector>
using namespace std;
   
   vector<int> searchRange(vector<int>& nums, int target) {
        vector<int> add{-1, -1};
        int left = 0,right = nums.size() - 1;
        while(left < right)
        {
            int mid = left + (right - left) / 2;//偶数个值时取中间值要取左边的那一个，
            //倘若取右边的哪一个会陷入死循环，由于right=mid的原因
            if(nums[mid] >= target)//将该数组分块分为[小于target的部分][大于等于target的部分]
            {                      
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }

        if(left > right || nums[left] != target) return add;
        add[0] = left;
        right = nums.size() - 1;
        while(left < right)
        {
            int mid = left + (right - left + 1) / 2;//同理
            if(nums[mid] > target)//将该数组分块分为[小于等于target的部分][大于target的部分]
            {
                right = mid - 1;
            }
            else
            {
                left = mid;
            }
        }
        add[1] = right;
        return add;
    }